package com.bruce.downloader.util;

import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

/**
 * 日志工具类
 * <br>CreateDate  2021/09/14 16:22:18
 *
 * @author luotuan
 * @version 1.0.0
 */
public class LogUtils {

    /**
     * info日志
     *
     * @param msg  日志信息
     * @param args 额外参数
     *
     *             <br>CreateDate 2021/09/14 16:26:37
     * @author luotuan
     * @since 1.0.0
     **/
    public static void info(String msg, Object... args) {
        print(msg, "-info-", args);
    }

    /**
     * error日志
     *
     * @param msg  日志信息
     * @param args 参数
     *
     *             <br>CreateDate 2021/09/14 16:26:46
     * @author luotuan
     * @since 1.0.0
     **/
    public static void error(String msg, Object... args) {
        print(msg, "-error-", args);
    }

    private static void print(String msg, String level, Object... args) {
        if (args != null && args.length > 0) {
            msg = String.format(msg.replace("{}", "%s"), args);
        }
        String name = Thread.currentThread().getName();
        System.out.println(LocalTime.now().format(DateTimeFormatter.ofPattern("hh:mm:ss")) + " " + name + level + msg);
    }
}
